package thread;

/**
 * sleep方法要求我们必须处理中断异常
 * 当一个线程调用sleep方法处理睡眠阻塞的过程中如果此时线程的interrupt方法被调用，那么
 * 此时该线程的睡眠阻塞状态会被打断，sleep方法就会抛出中断异常
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread t1=new Thread("li"){
            public void run(){
                System.out.println("睡着了");
                try {
                    Thread.sleep(5000000);
                    System.out.println("睡醒了");
                } catch (InterruptedException e) {
                    System.out.println("干嘛呢");
                }
            }
        };
        Thread t2=new Thread("ying"){
          public void run(){
              for (int i=0;i<5;i++){
                  System.out.println("80");
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              System.out.println("搞定");
              t1.interrupt();
          }
        };
        t1.start();
        t2.start();
    }
}
